﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;

namespace ApplLogic.ApplClasses
{
    [Serializable]
    public enum eType
    {
        WANTED,
        FORBIDDEN
    }

    [Serializable]
    public class ApplSingleRequest
    {
        private ApplWorker m_ApplWorker;
        private ApplShift m_ApplShift;
        private eType m_Type;

        public ApplWorker ApplWorker
        {
            get { return m_ApplWorker; }
            set { m_ApplWorker = value; }
        }

        public ApplShift ApplShift
        {
            get { return m_ApplShift; }
            set { m_ApplShift = value; }
        }

        public eType Type
        {
            get { return m_Type; }
            set { m_Type = value; }
        }

        public static string ConvertEnumTypeToString(eType type)
        {
            string asString = string.Empty;
            switch (type)
            {
                case eType.WANTED:
                    asString = "WANTED";
                    break;
                case eType.FORBIDDEN:
                    asString = "FORBIDDEN";
                    break;
                default:
                    break;
            }
            return asString;
        }

        public static eType ConvertStringToEnum(string stringType)
        {
            eType type = eType.WANTED;
            switch (stringType)
            {
                case "WANTED":
                    type = eType.WANTED;
                    break;
                case "FORBIDDEN":
                    type = eType.FORBIDDEN;
                    break;
                default:
                    break;
            }
            return type;
        }

        public ApplSingleRequest DeepClone()
        {
            MemoryStream ms = new MemoryStream();
            BinaryFormatter bf = new BinaryFormatter();
            bf.Serialize(ms, this);
            ms.Position = 0;
            ApplSingleRequest obj = (ApplSingleRequest)bf.Deserialize(ms);
            ms.Close();
            return obj;
        }

        public override string ToString()
        {
            return string.Format("\n WorkerFullName: {0}\n ShiftName {1}\n Type: {2}\n",
                                 m_ApplWorker.PersonalDetails.FullName, m_ApplShift.Name,
                                 ConvertEnumTypeToString(m_Type));
        }

    }
}
